// pages/notepad/notepad.js
var app = getApp();
var utils = require('../../utils/util.js');

var httpUrl = getApp().globalData.httpUrl;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        dataTime: utils.formatData(new Date())
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {},
    //录入健康记事簿  成功 跳转首页
    oNnotepadTap: function(e) {
        var that = this;
        var nameheight = e.detail.value.nameheight;
        var nameweight = e.detail.value.nameweight;
        var namehead = e.detail.value.namehead;
        var namebust = e.detail.value.namebust;
        var nametooth = e.detail.value.nametooth;
        var namevision = e.detail.value.namevision;
        var namehearing = e.detail.value.namehearing;
        if (nameheight != 0 && nameweight != 0 && namehead != 0 && namebust != 0 && nametooth != 0 && namevision != 0 && namehearing != 0) {
            utils.http(httpUrl + "/mobile/member/add_health", {
                date: that.data.dataTime,
                height: nameheight, //类型：Number  必有字段  备注：身高
                weight: nameweight, //类型：Number  必有字段  备注：日中
                head_cir: namehead, //类型：String  必有字段  备注：头围
                bust_cir: namebust, //类型：String  必有字段  备注：胸围
                tooth: nametooth, //类型：String  必有字段  备注：牙齿
                vision: namevision, //类型：String  必有字段  备注：视力
                hearing: namehearing, //类型：String  必有字段  备注：听力
            }, function(res) {
                if (res.state == 1) {
                   // console.log(res);
                    wx.switchTab({
                        url: '../index/index'
                    })
                } else {
                    utils.message(res.datas);
                }
            })
        }else{
            if (nameheight == 0){
                wx.showToast({
                    title: '请输入身高',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (nameweight == 0) {
                wx.showToast({
                    title: '请输入体重',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namehead == 0) {
                wx.showToast({
                    title: '请输入头围',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namebust == 0) {
                wx.showToast({
                    title: '请输入胸围',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (nametooth == 0) {
                wx.showToast({
                    title: '请输入牙齿',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if (namevision == 0) {
                wx.showToast({
                    title: '请输入视力',
                    image: '/images/error.png',
                    duration: 2000
                })
            }
            else if(namehearing == 0) {
                wx.showToast({
                    title: '请输入听力',
                    image: '/images/error.png',
                    duration: 2000
                })
            }

        }

    },
    //查看历史纪录
    oNhistoriesDataTap: function(e) {
        wx.navigateTo({
            url: '../historiesData/historiesData',
        })
    },
})